package org.lemon.transport.context.auth;

import org.lemon.transport.context.service.TransportContext;
import org.server.transport.gen.SessionProto;

import java.util.UUID;

public class SessionInfoCreator {

    public static SessionProto.SessionInfoProto create(ValidateDeviceCredentialsResponse msg, TransportContext transportContext, UUID sessionId) {
        return getSessionInfoProto(msg, transportContext.getServiceId(), sessionId);
    }

    private static SessionProto.SessionInfoProto getSessionInfoProto(ValidateDeviceCredentialsResponse msg, String nodeId, UUID sessionId) {
        return SessionProto.SessionInfoProto.newBuilder()
                .setNodeId(nodeId)
                .setSessionIdMSB(sessionId.getMostSignificantBits())
                .setSessionIdMSB(sessionId.getMostSignificantBits())
                .setTenantId(msg.getDeviceInfo().getTenantId().getValue())
                .setProjectId(msg.getDeviceInfo().getProjectId())
                .setDeviceId(msg.getDeviceInfo().getDeviceId())
                .setDeviceName(msg.getDeviceInfo().getDeviceName())
                .setDeviceType(msg.getDeviceInfo().getDeviceType())
                .setDeviceProfileId(msg.getDeviceInfo().getDeviceProfileId())
                .build();
    }
}
